<template>
  <div class="close-sent-box">
    <el-card class="header-card-box">
      <div class="header">
        <Describe :describe="value" />
        <div class="action">
          <span>
            <!-- <el-button type="primary"
                       @click="handerCancelClose">取消合约关闭</el-button> -->
          </span>
          <span>
            <el-button type="primary"
                       @click="handerRecallClose">撤回合约关闭</el-button>
          </span>
          <span class="cancel">
            <el-button plain
                       @click="cancel">取消</el-button>
          </span>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import axios from 'axios'
import Describe from './Describe.vue'

export default {
  name: 'CloseSentHeader',
  components: { Describe },
  props: {
    value: {
      type: Object,
      default: () => { }
    }
  },
  computed: {
    values () {
      return this.value
    }
  },
  methods: {
    handerCancelClose () {
      this.$confirm('是否继续该操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getCancelClose()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handerRecallClose () {
      this.$confirm('是否继续该操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.getRecallClose()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    async getCancelClose () {
      try {
        let url = `/quotation/template/close/cancel`
        let response = await axios.put(url, { templateId: this.values?.templateId })
        console.log('response', response)
        this.$message({
          type: 'success',
          message: '操作成功'
        });
        this.cancel()
      } catch (error) {
        console.log('error', error)
      }
    },
    async getRecallClose () {
      try {
        let url = `/quotation/template/close/recall`
        let response = await axios.put(url, { templateId: this.values?.templateId })
        console.log('response', response)
        this.$message({
          type: 'success',
          message: '操作成功'
        });
        this.cancel()
      } catch (error) {
        console.log('error', error)
      }
    },
    cancel () {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
.header {
  height: 32px;
  line-height: 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-dropdown {
  /* padding: 0 10px; */
  padding-left: 10px;
}
.cancel {
  padding-left: 10px;
}
.action {
  /* display: flex; */
  width: 30%;
  text-align: end;
}
.action span {
  padding-left: 10px;
}
</style>